package com.egreen.terminal.controller;


import com.egreen.common.Result;
import com.egreen.terminal.service.ITransactionrecordsService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;

import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController;

import java.math.BigDecimal;
import java.util.List;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author cloudJiang
 * @since 2022-07-16
 */
@Slf4j
@RestController
@Api(tags = "终端交易接口")
@RequestMapping("/transactionrecords")
public class TransactionrecordsController {

    @Autowired
    ITransactionrecordsService iTransactionrecordsService;


    /**
     * 参数说明
     * tradingUser：产生交易的用户ID
     * tradingMoney:交易的金额
     * tradingTime：交易的时间（不在请求中，后端获取系统时间戳得到）
     * tradingPlace：交易产生的地点
     * serialNumber：交易产生的终端序列号
     * tradingComment：交易备注
     */
    @RequestMapping("recyclingAtTerminal")
    @ResponseBody
    @ApiOperation("在终端进行回收")
    Result recyclingAtTerminal(@RequestParam("trading_user") String tradingUser, @RequestParam("trading_money") String tradingMoney,
                               @RequestParam("trading_place") String tradingPlace, @RequestParam("serial_number") String serialNumber,
                               @RequestParam("trading_comment") String tradingComment){
        log.info("进入终端交易接口");
        return iTransactionrecordsService.recyclingAtTerminal(tradingUser,tradingMoney,tradingPlace,serialNumber,tradingComment);
    }

    /**
     * 根据终端序列号删除交易记录
     * @param serialNumber
     * @return
     */
    @RequestMapping("deleteTerminalTransaction")
    @ResponseBody
    @ApiOperation("根据终端序列号删除终端交易记录")
    Result deleteTerminalTransaction(@RequestParam("serial_number") String serialNumber){
        log.info("进入终端交易记录删除接口");
        return iTransactionrecordsService.deleteTerminalTransaction(serialNumber);
    }

    @RequestMapping("inquireTerminalTransaction")
    @ResponseBody
    @ApiOperation("根据终端序列号查询交易记录")
    List inquireTerminalTransaction(@RequestParam("serial_number") String serialNumber){
        log.info("进入根据终端序列号查询交易记录接口");
        return iTransactionrecordsService.inquireTerminalTransaction(serialNumber);
    }
}

